var purchaseorderId=sessionStorage.getItem("purchaseorderId")//订单号
receiptall()
function receiptall() {
    $.ajax({
        contentType: "application/json",
        type: "POST",
        url: root.orderInter.receiveGoodsList,
        cache: false, //禁用缓存
        dataType: "json",
        data: JSON.stringify({
            billNo: $("#billNo").val(),
            startDate: $("#startDate").val(),
            endDate: $("#endDate").val(),
            pageNumber:1,
            pageSize:20
        }),
        success: function(result) {
            receiptallList(result);
            $('.M-box3').pagination({
                pageCount: result.data.totalPage,
                jump: true,
                coping: true,
                prevContent: '上页',
                nextContent: '下页',
                callback: function (api) {
                   /* receiptall(api.getCurrent())*/
                }
            });
            $('.M-box3').pagination({
                pageCount: result.data.totalPage,
                jump: true,
                coping: true,
                prevContent: '上页',
                nextContent: '下页',
                callback: function(api) {
                    console.log(api.getCurrent());
                    $.ajax({
                        contentType: "application/json",
                        type: "POST",
                        url: root.orderInter.receiveGoodsList,
                        cache: false, //禁用缓存
                        dataType: "json",
                        data: JSON.stringify({
                            billNo: $("#billNo").val(),
                            startDate: $("#startDate").val(),
                            endDate: $("#endDate").val(),
                            pageNumber:api.getCurrent(),
                            pageSize:20
                        }),
                        success: function(result) {
                            receiptallList(result);
                        },
                        error: function(XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest);
                        }
                    });
                }
            });

        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });
}
var dataSource = new Array();
//table的数据源
var table;   //table对象
dataSource = [];
function receiptallList(data) {
    dataSource.splice(0, dataSource.length); //清空数组
    if (data.data != null && data.data != "") {
        $.each(data.data.result, function (i, field) {
            var rowData = new Array();
            rowData.push(field.billDate);
            rowData.push(field.billNo);
            rowData.push(field.receiveCompanyName);
            rowData.push(field.supplierName);
            rowData.push(field.limitTime);
            rowData.push(field.receiveAddress);
            rowData.push(field.skuNum);
            rowData.push(field.entryList);//商品信息
            dataSource.push(rowData);
        });

    }
    receiptallDataTable(dataSource);
}
function receiptallDataTable(dataSource) {
    var receiptalltables=""
    for(var i=0;i<dataSource.length;i++) {
        var curData= dataSource[i];
        var productStr=""
        var productData=curData[7]
        if(productData && productData.length>0){
            for(var j=0;j<productData.length;j++){
                var curPro = productData[j];
                productStr +='<div class="orer_item"><tr class="moretr hide"><td><span class="skuCodeall">'+curPro.skuCode+'</span></td><td><span class="skuNameall">'+curPro.skuName+'</span><span class="qtyall" style="display: none">'+curPro.qty+'</span></td><td>'+curPro.modelName+'</td><td>'+curPro.qty+''+curPro.skuUnitName+'</td><td></td><td></td><td></td><td></td></tr></div>';

            }
        }
        var receiptallhtml=''
        var valall = '<div class="list_more " onclick="showMore(this);"><span id="operText" style="color: #0f9ae0;">展开</span><i class="icon"></i></a></div>';

        receiptallhtml+='<tr><td style="width: 195px;"><input type="radio" name="relationbillNo" value="'+curData[1]+'">'+curData[0]+'</td><td style="width: 195px;">'+curData[1]+'</td><td style="width: 195px;">'+curData[2]+'</td>' +
            '<td style="width: 195px;">'+curData[3]+'</td><td style="width: 195px;">'+curData[4]+'</td><td style="width: 195px;">'+curData[5]+'</td><td style="width: 195px;">'+curData[6]+'</td><td style="width: 195px;">'+valall+'</td></tr>'+productStr+''

        receiptalltables+='<div class="orer_item"><table  style="width:100%;" class="receiptalltableall table table-border table-bg table-sort list_box_table"><tbody>'+receiptallhtml+'</tbody></table></div>'

    }
    $('.receiptalltable').empty().append(receiptalltables);

}
function showMore(dom) {
    var curDom = $(dom);
    console.log(curDom.parents('.orer_item'))
    var curTr = curDom.parents('.orer_item').find('.moretr');
    if(curTr.eq(0).hasClass('hide')){
        curTr.removeClass('hide');
        curDom.find('#operText').html('收起');
    }else{
        curTr.addClass('hide');
        curDom.find('#operText').html('展开');
    }

}
//关联
function relationdatas() {
    var datas={}
    var receiptOrderItems=[]
    for (var k=0;k<$($('input[name="relationbillNo"]:checked').parents()[3]).find('.skuCodeall').length;k++){
        datas={
            'skuCode':$($('input[name="relationbillNo"]:checked').parents()[3]).find('.skuCodeall')[k].innerHTML,
            'skuName':$($('input[name="relationbillNo"]:checked').parents()[3]).find('.skuNameall')[k].innerHTML,
            'quantity':$($('input[name="relationbillNo"]:checked').parents()[3]).find('.qtyall')[k].innerHTML
        }
        receiptOrderItems.push(datas)
    }
    var relationbillNo=$('input[name="relationbillNo"]:checked').val()

    if(relationbillNo==undefined){
        $.Huimodalalert('请关联接货单',2000);
    }else {
        var user_data = {
            "orderId":purchaseorderId,
            "receiptNo":relationbillNo,
            "receiptOrderItems":receiptOrderItems
        }
        var succCallBack = function (data, status, response) {
            if (data.code == "0") {
                layer.msg("关联成功", {icon: 6, time: 1000}, function () {
                    sessionStorage.setItem("relationbillNo", relationbillNo);
                    window.parent.relationbillNo();; // 父页面刷新
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                });

            } else {
                layer.msg(data.message, {icon: 5, time: 1000}, function () {
                });
            }
        }
        web.doAjax(root.orderInter.checkReceiptOrderProductCount, 'post', user_data, succCallBack,1);

    }


}